﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Drawing.Design;
using System.Linq;
using System.Threading;
using System.Windows.Forms;
using WeForms.Design;

namespace WeForms
{
    [Editor(typeof(WeTabSideBarControlListEditor), typeof(UITypeEditor))]
    [Editor(typeof(WeTabSideBarControlListEditor), typeof(UITypeEditor))]
    public class WeTabSideBarControlList : IList<WeTabSideBarControl>, ICollection<WeTabSideBarControl>, IEnumerable<WeTabSideBarControl>, IList, ICollection, IEnumerable
    {
        private readonly IList _controls;
        [NonSerialized]
        private object _syncRoot;

        public WeTabSideBarControlList()
            : this(new List<WeTabSideBarControl>())
        {
        }

        public WeTabSideBarControlList(IList proxy)
        {
            this._controls = proxy;
        }

        public void Add(WeTabSideBarControl item)
        {
            this._controls.Add(item);
        }

        public void Clear()
        {
            this._controls.Clear();
        }

        public bool Contains(WeTabSideBarControl item)
        {
            return this._controls.Contains(item);
        }

        public void CopyTo(WeTabSideBarControl[] array, int arrayIndex)
        {
            this._controls.CopyTo(array, arrayIndex);
        }

        public IEnumerator<WeTabSideBarControl> GetEnumerator()
        {
            return new WeTabSideBarControlEnumerator(this);
        }

        public int IndexOf(WeTabSideBarControl item)
        {
            return this._controls.IndexOf(item);
        }

        public void Insert(int index, WeTabSideBarControl item)
        {
            this._controls.Insert(index, item);
        }

        public bool Remove(WeTabSideBarControl item)
        {
            this._controls.Remove(item);
            return true;
        }

        public void RemoveAt(int index)
        {
            this._controls.RemoveAt(index);
        }

        void ICollection.CopyTo(Array array, int arrayIndex)
        {
            if ((array != null) && (array.Rank != 1))
            {
                throw new ArgumentException("Multidimensional arrays not supported");
            }
            try
            {
                Array.Copy(this._controls.Cast<WeTabSideBarControl>().ToArray<WeTabSideBarControl>(), 0, array, arrayIndex, this.Count);
            }
            catch (ArrayTypeMismatchException)
            {
                throw new ArgumentException("Invalid array Type");
            }
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            return this.GetEnumerator();
        }

        int IList.Add(object item)
        {
            if (!(item is WeTabSideBarControl))
            {
                throw new ArgumentException("item has the wrong type", "item");
            }
            this.Add((WeTabSideBarControl)item);
            return (this.Count - 1);
        }

        bool IList.Contains(object item)
        {
            return ((item is WeTabSideBarControl) && this.Contains((WeTabSideBarControl)item));
        }

        int IList.IndexOf(object item)
        {
            if (item is WeTabSideBarControl)
            {
                return this.IndexOf((WeTabSideBarControl)item);
            }
            return -1;
        }

        void IList.Insert(int index, object item)
        {
            if (!(item is WeTabSideBarControl))
            {
                throw new ArgumentException("item has the wrong type", "item");
            }
            this.Insert(index, (WeTabSideBarControl)item);
        }

        void IList.Remove(object item)
        {
            if (item is WeTabSideBarControl)
            {
                this.Remove((WeTabSideBarControl)item);
            }
        }

        public int Count
        {
            get
            {
                return this._controls.Count;
            }
        }

        public bool IsReadOnly
        {
            get
            {
                return this._controls.IsReadOnly;
            }
        }

        public WeTabSideBarControl this[int index]
        {
            get
            {
                return (WeTabSideBarControl)this._controls[index];
            }
            set
            {
                this._controls[index] = value;
            }
        }

        bool ICollection.IsSynchronized
        {
            get
            {
                return false;
            }
        }

        object ICollection.SyncRoot
        {
            get
            {
                if (this._syncRoot == null)
                {
                    Interlocked.CompareExchange(ref this._syncRoot, new object(), null);
                }
                return this._syncRoot;
            }
        }

        bool IList.IsFixedSize
        {
            get
            {
                return false;
            }
        }

        object IList.this[int index]
        {
            get
            {
                return this[index];
            }
            set
            {
                if (!(value is WeTabSideBarControl))
                {
                    throw new ArgumentException("item has the wrong type", "value");
                }
                this[index] = (WeTabSideBarControl)value;
            }
        }

        private class WeTabSideBarControlEnumerator : IEnumerator<WeTabSideBarControl>, IDisposable, IEnumerator
        {
            private int _current;
            private readonly WeTabSideBarControlList _list;
            private readonly int _originalCount;

            public WeTabSideBarControlEnumerator(WeTabSideBarControlList list)
            {
                this._list = list;
                this._originalCount = list.Count;
                this._current = -1;
            }

            public void Dispose()
            {
            }

            public bool MoveNext()
            {
                if ((this._current < (this._list.Count - 1)) && (this._current < (this._originalCount - 1)))
                {
                    this._current++;
                    return true;
                }
                return false;
            }

            public void Reset()
            {
                this._current = -1;
            }

            public WeTabSideBarControl Current
            {
                get
                {
                    if (this._current == -1)
                    {
                        return null;
                    }
                    return this._list[this._current];
                }
            }

            object IEnumerator.Current
            {
                get
                {
                    return this.Current;
                }
            }
        }
    }

 



}
